﻿using MediatR;
using SlaughterItem.Common.Domains.ListWeek2;
using SlaughterItem.Common.Domains.SetUpScale;
using SlaughterItem.Common.Dtos;
using SlaughterItem.Common.Infrastructures.Interfaces;
using SlaughterItem.Enum;

namespace GetSlaughterItem.API.Application.Commands.Week02.GetScaleType01
{
    /// <summary>
    /// 获取磅秤分类表数据
    /// </summary>
    public class GetScaleTypeHandler : IRequestHandler<GetScaleTypeCommand, Result>
    {
        public GetScaleTypeHandler(IBaseRepositoryGet<ScaleType> baseRepositoryGet)
        {
            this.baseRepositoryGet = baseRepositoryGet;
        }

        public IBaseRepositoryGet<ScaleType> baseRepositoryGet { get; set; }
        public async Task<Result> Handle(GetScaleTypeCommand request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CommonErrorCode.Search };
            var list = baseRepositoryGet.GetAll().ToList();
            if (list != null)
            {
                result.Data = list;
                result.Code = (int)CommonErrorCode.Success;
                return result;
            }
            else
            {
                return result;
            }
        }
    }
}
